package com.taotao.appender;

import cn.hutool.json.JSONUtil;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
import org.apache.logging.log4j.core.config.plugins.PluginFactory;

@Plugin(name = "CustomAppender", category = "Core", elementType = Appender.ELEMENT_TYPE)
public class CustomAppender extends AbstractAppender {

    // 构造函数
    protected CustomAppender(String name, Layout<?> layout) {
        super(name, null, layout, false);
    }

    // 实现append方法，不执行任何操作
    @Override
    public void append(LogEvent event) {
        System.out.println(event.getMessage().getFormattedMessage());
    }

    // 工厂方法，用于创建NoOpAppender实例
    @PluginFactory
    public static CustomAppender createAppender(@PluginAttribute("name") String name) {
        return new CustomAppender(name, null);
    }
}